﻿{extend name="public:base" /}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <div class="table-responsive">

                        <table class="table table-striped">
                            <tr>
                                <th>视频号名称</th>
                                <th>账号标识</th>
                                <th>登录凭证</th>
                                <th>操作</th>
                            </tr>
                            <tr>
                                <td>
                                    <input type="text" class="form-control name" placeholder="请输入视频号名称" >
                                </td>
                                <td>
                                    <input type="text" class="form-control sessionId" placeholder="请输入账号标识" >
                                </td>
                                <td>
                                    <textarea class="cookie" cols="40" rows="3" placeholder="请输入登录凭证" ></textarea>
                                </td>
                                <td>
                                    <a href="javascript: void(0)" class="btn btn-white btn-sm save"><i class="iconfont icon-edit"></i> 保存
                                    </a>
                                </td>
                            </tr>
                            {volist name="list" id="vo" key="index"}
                            <tr>
                                <td>
                                    <input type="text" class="form-control edit-name" value="{$vo.name}" placeholder="请输入视频号名称" >
                                </td>
                                <td>
                                    <input type="text" class="form-control edit-sessionId" value="{$vo.sessionId}" placeholder="请输入账号标识" >
                                </td>
                                <td>
                                    <textarea class="edit-cookie" cols="40" rows="3" placeholder="请输入登录凭证" >{$vo.cookie}</textarea>
                                </td>
                                <td>
                                    <a href="javascript: void(0)" data-id="{$vo.id}" data-index="{$index-1}" class="btn btn-white btn-sm edit-save"><i class="iconfont icon-edit"></i> 保存
                                    </a>
                                    <a href="{:url(delAccount, ['id' => $vo.id])}" class="btn btn-white btn-sm ajax-del"><i class="iconfont icon-trash"></i> 删除
                                    </a>
                                </td>
                            </tr>
                            {/volist}
                        </table>
                        {if !empty($list)}{$list->render()}{/if}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>{/block}

{block name="js"}
<script>
    $('.save').click(function () {
        var name = $('.name').val();
        var sessionId = $('.sessionId').val();
        var cookie = $('.cookie').val();
        if (name == '' || sessionId == '' || cookie == '') {
            layer.msg('请填写完整信息', {icon: 2});
            return false;
        }

        layer.load(1)

        $.post('/admin/manage/saveAccount', {
           name, sessionId, cookie
        }, res => {
            layer.closeAll();
            if (res.result == 1) {
                layer.msg('保存成功', {icon: 1, time: 1000}, () => {
                    window.location.reload();
                });
            } else {
                lay.msg('保存失败', {icon: 2});
            }
        }, 'json')
    })
    $('.edit-save').click(function () {
        var id = $(this).data('id');
        var index = $(this).data('index');
        var name = $('.edit-name').eq(index).val();
        var sessionId = $('.edit-sessionId').eq(index).val();
        var cookie = $('.edit-cookie').eq(index).val();
        if (name == '' || sessionId == '' || cookie == '') {
            layer.msg('请填写完整信息', {icon: 2});
            return false;
        }

        layer.load(1)

        $.post('/admin/manage/saveAccount', {
            id, name, sessionId, cookie
        }, res => {
            layer.closeAll();
            if (res.result == 1) {
                layer.msg('保存成功', {icon: 1, time: 1000}, () => {
                    // window.location.reload();
                });
            } else {
                lay.msg('保存失败', {icon: 2});
            }
        }, 'json')
    })
</script>{/block}